﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Zebra.Utility
{
    public partial class BaseGridViewSearch : UserControl
    {
        public string[] Columns;

        public event EventHandler SearchClick;
        public event EventHandler TextChangedSearch;
        public event DataGridViewCellEventHandler DataRowSelected;
               
        private object _selectedItem;
        public object SelectedItem
        {
            get { return _selectedItem; }
        }
        public object Datasource { get; set; }      

        #region Methods
        public BaseGridViewSearch()
        {
            InitializeComponent();
        }
       
        #endregion

        #region Events
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string s = txtSearch.Text.Trim();
            SearchClick(sender, e);
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            txtSearch.Text = string.Empty;
        }
        private void dgvMain_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                _selectedItem = BaseGridview.gvMain.Rows[e.RowIndex].DataBoundItem;

            if (DataRowSelected != null)
                DataRowSelected(_selectedItem, e);
        }

        #endregion

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            string s = txtSearch.Text.Trim().ToLower();
            //if (s.Length > 0)
           // {
                TextChangedSearch(s, e); 
            //}
        }
    }
}
